const testModel = require("../models/test");
const createModel = require("../models/createModel");
const { createStudentModel, findStudent } = require("../models/StudentModel");
let status = function (data, res) {
  if (data) {
    res.send({
      meta: {
        status: 200,
        msg: "添加成功",
      },
      data,
    });
    return;
  } else {
    res.send({
      meta: {
        status: 500,
        msg: "添加失败",
      },
      data: null,
    });
  }
  res.send(data);
};

module.exports = {
  async create(req, res) {
    let postData = req.body;
    let data = await createModel(postData);
    status(data);
  },
  async findAll(req, res) {
    let data = await testModel.find({}).catch((err) => console.log(err));
    res.send(data);
  },
  async addStudent(req, res) {
    let studentData = req.body;
    let data = await createStudentModel(studentData);
    status(data, res);
  },
  async findStudents(req, res) {
    let data = await findStudent();
    status(data, res);
  },
};
